package org.alex.samples.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.alex.samples.javabean.ExamScoreVO;
import org.alex.samples.javabean.ExamSubjectVO;
import org.alex.samples.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/student")
public class StudentController {
	
	@Autowired
	private IStudentService iStudentService;
	
	@RequestMapping(value = "/showStudent")
	public String showStudent(HttpSession session, Model model) {
		String userId = (String) session.getAttribute("userId");
		List<ExamSubjectVO> examSubjectList = iStudentService.getSubjectList(userId);
		model.addAttribute("examSubjectList", examSubjectList);
		return "student/subjectScore";
	}
	
	@ResponseBody
	@RequestMapping(value = "/showScore", method = RequestMethod.POST)
	public ExamScoreVO showScore(Integer scoreId) {
		ExamScoreVO examScoreVO = iStudentService.getScoreById(scoreId);
		return examScoreVO;
	}
	
}
